package pers.lance.interceptor.controller;

import pers.lance.interceptor.db.DB;
import pers.lance.interceptor.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.SessionAttributes;

/**
 * @ Author     ：LILA3
 * @ Date       ：Created in 3:16 PM 7/25/2018
 */
@Controller
@RequestMapping("/user")
@SessionAttributes(value={"user"},types={User.class})
public class UserController {

    @RequestMapping(value = "/login", method = RequestMethod.POST)
    public String login(User user, Model model){
        if(DB.usersTable.contains(user)){
            model.addAttribute("user", user);
            return "redirect:/items/lists";
        }else {
            return "redirect:/index.jsp";
        }
    }
}
